package client.comm.baoding.ui.vm


import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.baoding.api.bean.TradeIndex
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.baoding.api.bean.UserAddress

class ZhihuanViewModel(app: Application) : MiddleVm(app) {

    val tradeCall = MutableLiveData<JsonResult<TradeIndex>>()
    val zhihuanRet = MutableLiveData<JsonResult<Ret>>()
    val isLoading = MutableLiveData<Boolean>(false)
    val isShowing = MutableLiveData<Boolean>(false)
    val isRef = MutableLiveData<Boolean>(false)
    val pageTrade = MutableLiveData<Int>(0)


    fun getListCall() {
        if (isLoading.value!!)
            return
        hold({
            server.trade_index(pageTrade.value!!)
        }, {
            pageTrade.value = pageTrade.value!! + 1
        }, {
            tradeCall.value = it
        }, complete = {
            isLoading.value = false
        })
    }


    fun zhihuan(order_id: String, goods_id: String) {
        hold(
            {
                server.goods_displace(order_id, goods_id)
            },
            {
                isLoading.value = true
            }, {
                zhihuanRet.value = it
            }, {
            }, {
                isLoading.value = false
            }
        )
    }


}